package org.soenea.doitall.domain.model.group.mapper;

import java.sql.SQLException;

import org.dsrg.soenea.domain.MapperException;
import org.dsrg.soenea.domain.mapper.IOutputMapper;
import org.dsrg.soenea.domain.mapper.LostUpdateException;
import org.soenea.doitall.domain.model.group.data.*;
import org.soenea.doitall.domain.model.group.*;

public class GroupOutputMapper implements IOutputMapper<Long, Group> {
	public void insert(Group g) throws MapperException {
		try {
			GroupTDG.insert(g.getId(), g.getGroupName(), g.getDescription());
		} catch (final SQLException e) {
			throw new MapperException(e);
		}
	}

	public void update(Group g) throws MapperException, LostUpdateException {
		try {
			int count = GroupTDG.update(g.getId(), g.getVersion(), g.getGroupName(), g.getDescription());
			if (count == 0)
				throw new LostUpdateException("Group " + g.getId() + " has already been updated.");
		} catch (final SQLException e) {
			throw new MapperException(e);
		}
	}

	public void delete(Group d) throws MapperException {
		try {
			GroupTDG.delete(d.getId(), d.getVersion());
		} catch (final SQLException e) {
			throw new MapperException(e);
		}
	}

	@Override
	public void cascadeInsert(Group d) throws MapperException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void cascadeUpdate(Group d) throws MapperException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void cascadeDelete(Group d) throws MapperException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void validateInsert(Group d) throws MapperException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void validateUpdate(Group d) throws MapperException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void validateDelete(Group d) throws MapperException {
		// TODO Auto-generated method stub
		
	}
}

